#include "mewindow.h"
#include "ui_mewindow.h"
#include <QPixmap>
#include <QDir>
#include <QFile>
#include <QTextStream>

Mewindow::Mewindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Mewindow)
{
    ui->setupUi(this);
    connect(ui->bckBtn, &QPushButton::clicked,
            this,        &Mewindow::back);

    //显示用户头像
    QString picPath = QDir::currentPath() + "/userImformation/avatar.png";     //用户头像的路径
    QPixmap pix(picPath);

    if (!pix.isNull()) {
        ui->labelPhoto->setPixmap(pix);
        ui->labelPhoto->setScaledContents(true);   // 让图片填满 label
    } else {
        ui->labelPhoto->setText("用户头像未找到");
    }

    //显示用户名
    QString filePath = QDir::currentPath() + "/userImformation/userName.txt";         //用户名的路径
    QFile file(filePath);

    if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QTextStream in(&file);
        in.setCodec("UTF-8");               // 如有中文
        ui->labelUserName->setText(in.readAll());
        file.close();
    } else {
        ui->labelUserName->setText("用户名未找到");
    }
    ui->labelUserName->setAlignment(Qt::AlignCenter);

    //显示用户其他信息
    QString filePath1 = QDir::currentPath() + "/userImformation/other.txt";       // 用户其他信息的路径
    QFile file1(filePath1);

    if (file1.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QTextStream in(&file1);
        in.setCodec("UTF-8");               // 如有中文
        ui->labelOther->setText(in.readAll());
        file1.close();
    } else {
        ui->labelOther->setText("其他信息未找到");
    }
    ui->labelOther->setAlignment(Qt::AlignCenter);


}



Mewindow::~Mewindow()
{
    delete ui;
}
